package com.slt.developkitweb.crm;

import com.alibaba.fastjson.JSON;
import org.springframework.web.bind.annotation.RequestBody;

import java.util.Map;
import java.util.Optional;
import java.util.UUID;

/***
 * @author shalongteng
 * @date 2024年04月15日 14:13
 **/
public class TestCrm {

//    public NetResponse<String> testPost(@RequestBody Map<String, String> map) {
//        return call(() -> {
//            String url = Optional.ofNullable(map.get("url")).orElseThrow(()-> new SysException(PaasReturnEnum.error.code,"url必填"));
//            String path = Optional.ofNullable(map.get("path")).orElseThrow(()-> new SysException(PaasReturnEnum.error.code,"path必填"));
//            String appId = Optional.ofNullable(map.get("appId")).orElseThrow(()-> new SysException(PaasReturnEnum.error.code,"appId必填"));
//            String securityKey = Optional.ofNullable(map.get("securityKey")).orElseThrow(()-> new SysException(PaasReturnEnum.error.code,"securityKey必填"));
//            String sm2PriKey = Optional.ofNullable(map.get("sm2PriKey")).orElseThrow(()-> new SysException(PaasReturnEnum.error.code,"sm2PriKey必填"));
//            String data = Optional.ofNullable(map.get("data")).orElseThrow(()-> new SysException(PaasReturnEnum.error.code,"data必填"));
//
//            try {
//                CrmHttpCli crmHttpCli = new CrmHttpCli(url,path);
//                PaasRequest request = new PaasRequest();
//                request.setRequestId(String.valueOf(UUID.randomUUID()));
//                request.setVersion("1.0.0");
//                request.setAppId(appId);
//                request.setSecurityKey(securityKey);
//                request.setData(data);
//                request.setHmac(GmwSm2Utils.sign(Signer.toSignContent(request, null), sm2PriKey));
//                String body = JSON.toJSONString(request);
//                return crmHttpCli.httpPost(body);
//            } catch (Exception e) {
//            }
//        });
//    }

    public static void main(String[] args) throws Exception {
        CrmHttpCli crmHttpCli = new CrmHttpCli("url","path");
        PaasRequest request = new PaasRequest();
        request.setRequestId(String.valueOf(UUID.randomUUID()));
        request.setVersion("1.0.0");
        request.setAppId("Rxr6VEZq");
        request.setSecurityKey("d2206746a9917f112adf569d7b7c2f0ca68b9ebd");
        request.setData("123");
        request.setHmac(GmwSm2Utils.sign(Signer.toSignContent(request, null), "993b6bc20a60d0aad98d090c4bb2507608f12e0bb80e25c747bfac3b5d0e49ec"));
        String body = JSON.toJSONString(request);
        crmHttpCli.httpPost(body);
    }
}
